package com.zlm.common.enums;

import org.apache.commons.lang3.tuple.Pair;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: duyufu
 * @Date: 2019/4/23 16:16
 */
public enum QuickEntryEnum {

    POSITION_HOT(1,"热门职位", "isHot", 1,  "http://www.zhaolemo.com/emp/position/POSITION_HOT.png"),
    POSITION_ORG_URGENT(2,"企业急招","isUrgent", 1,  "http://www.zhaolemo.com/emp/position/POSITION_ORG_URGENT.png"),
    POSITION_HOURLY(3,"小时工","workType", 3,  "http://www.zhaolemo.com/emp/position/POSITION_HOURLY.png"),
    POSITION_VACATION(4,"寒暑假工","workType", 4, "http://www.zhaolemo.com/emp/position/POSITION_SUMMER.png"),
    POSITION_PRACTICE(5,"实习生","workType", 5, "http://www.zhaolemo.com/emp/position/POSITION_PRACTICE.png");

    private Integer code;

    private String name;

    private String paramType;

    private Integer param;

    private String icon;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getParamType() {
        return paramType;
    }

    public void setParamType(String paramType) {
        this.paramType = paramType;
    }

    public Integer getParam() {
        return param;
    }

    public void setParam(Integer param) {
        this.param = param;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    QuickEntryEnum(Integer code, String name, String paramType, Integer param, String icon) {
        this.code = code;
        this.name = name;
        this.paramType = paramType;
        this.param = param;
        this.icon = icon;
    }

    public static List<Map<String,Object>> getQuickEntryEnum(){
        List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
        Map<String,Object> map;
        for(QuickEntryEnum typeEnum:QuickEntryEnum.values()){
            map= new HashMap<String, Object>();
            map.put("code", typeEnum.getCode());
            map.put("name", typeEnum.getName());
            map.put("paramType", typeEnum.getParamType());
            map.put("param", typeEnum.getParam());
            map.put("icon", typeEnum.getIcon());
            list.add(map);
        }
        return list;
    }

    public static String getQuickEntryEnumJsonString(){
        StringBuilder builder = new StringBuilder("{");
        for (QuickEntryEnum typeEnum:QuickEntryEnum.values()) {
            builder.append("\""+typeEnum.getCode()+"\":\""+ typeEnum.getName()+"\":\""
                               +typeEnum.getParamType()+"\":\""+ typeEnum.getParam()+"\":\""
                               +typeEnum.getIcon()+"\",");
        }
        String json=builder.substring(0, builder.length()-1)+"}";
        return json;
    }

    /**
     * 根据code得到name和icon
     * @param code
     * @return
     */
    public static Pair<String, String> getNameIconByCode(Integer code) {
        for(QuickEntryEnum typeEnum:QuickEntryEnum.values()){
            if(code.equals(typeEnum.getCode())){
                return Pair.of(typeEnum.getName(),typeEnum.getIcon());
            }
        }
        return null;
    }

    public static Map<String,Object> getParamsByCode(Integer code) {
        for(QuickEntryEnum typeEnum:QuickEntryEnum.values()){
            if (code.equals(typeEnum.getCode())) {
                Map<String, Object> map = new HashMap<>();
                map.put("code", typeEnum.getCode());
                map.put("name", typeEnum.getName());
                map.put("paramType", typeEnum.getParamType());
                map.put("param", typeEnum.getParam());
                map.put("icon", typeEnum.getIcon());
                return map;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return "PositionTypeEnum{" +
                "code=" + code +
                ", name='" + name + '\'' +
                ", paramType='" + paramType + '\'' +
                ", param=" + param +
                ", icon='" + icon + '\'' +
                '}';
    }}
